<extend name="./Application/Home/View/Layouts/application.html"/>

<block name="content">

    <div class="slick meun">

        <volist name="galleries" id="gallery">
            <a href="javascript:void(0);">
                <img class="img-responsive" src="{{$gallery.img}}" alt="图片一" style="width: 354px;height: 222px;"/>
            </a>
        </volist>

    </div>

    <section class="detail">
        <hgroup class="product">
            <h1>{{$products.name}}</h1>
            <h2 id="price">¥ {{$products.price}}元</h2>
        </hgroup>
        <p>{{$products.description}}</p>
    </section>

    <section class="operate" data-id="{{$products.id}}">
        <span id="btn-buy">立即购买</span>
        <span id="btn-cart-plus">加入购物车</span>
    </section>

</block>
<block name="js">
    <script>
        $(function () {
            //立刻购买
            $("#btn-buy").click(function () {
                var product_id = $(this).parent('.operate').data('id');
                $.post("{{:U('Cart/add')}}", {product_id: product_id}, function (info) {
                    if (info.status == 0) {
                        alert(info.msg);
                        location.href = "{{:U('Customer/login')}}";
                    } else {
                        location.href = "{{:U('Order/index')}}";
                    }
                })
                return false;
            })

            //加入购物车
            $("#btn-cart-plus").click(function () {
                var product_id = $(this).parent('.operate').data('id');
                $.post("{{:U('Cart/add')}}", {product_id: product_id}, function (info) {
                    if (info.status == 0) {
                        alert(info.msg);
                        location.href = "{{:U('Customer/login')}}";
                    } else {
                        alert(info.msg);
                        window.location.reload();
                    }
                })
                return false;
            })
        })
    </script>
</block>